$(function () {
    $('#page').load('page.html');
})


function deleteById(id) {
    let data=myAjax("/user/delete",{id:id},"post");
    data=data.result;
    if (data==1){
        alert("删除成功！");
        $('#middle-reght').load('user/user.html');
    }else {
        alert("删除失败！");
    }
}

function FindAll() {
    let code=localStorage.getItem("code");
    if (code==null){
        code=$.trim($("#code").val());
    }else {
        code=code;
    }
    let da={
        code:code,
        typeName:$("#user-Type").val(),
        name:$.trim($("#name").val()),
        sex:$("#sex").val(),
        education:$.trim($("#education").val()),
        groupCode:$("#groupCode").val(),
        pageSize:$("#pageSize").val(),
        pageNum:$("#pageNum").val(),
    }
    let data=myAjax("/user/findCondition",da,"post");
    $("#pageCount").text(data.data.total);
    data=data.data.list;
    let html='';
    for (let i=0;i<data.length;i++){
        html+='        <tr>\n' +
            '            <td>'+data[i].id+'</td>\n' +
            '            <td>'+data[i].code+'</td>\n' +
            '            <td>'+data[i].name+'</td>\n' +
            '            <td>'+data[i].sex+'</td>\n' +
            '            <td>'+data[i].age+'</td>\n' +
            '            <td>'+data[i].education+'</td>\n' +
            '            <td>'+data[i].university+'</td>\n' +
            '            <td><div class="biaos">'+data[i].naative+'</div></td>\n' +
            '            <td><div class="biaos">'+data[i].address+'</div></td>\n' +
            '            <td>'+data[i].phone+'</td>\n' +
            '            <td>'+data[i].otherphone+'</td>\n' +
            '            <td>'+data[i].groupCode+'</td>\n' +
            '            <td>'+data[i].timeAdmission+'</td>\n' +
            '            <td>'+data[i].frequency+'</td>\n' +
            '            <td>'+data[i].classroom+'</td>\n' +
            '            <td>'+data[i].position+'</td>\n' +
            '            <td><input type="button" value="用户编辑" onclick="updataById('+data[i].id+',\''+data[i].typeName+'\')"><input type="button" value="角色编辑" onclick="updataRoleById('+data[i].id+',\''+data[i].name+'\')"><input type="button" value="权限编辑" onclick="userJurisdictionUpdateById('+data[i].id+',\''+data[i].name+'\')"><input type="button" value="删除角色" onclick="deleteById('+data[i].id+')"></td>\n' +
            '        </tr>';
    }
    localStorage.removeItem("code");
    $("#userFandAll").html(html);
}

function updataById(id,name){
    localStorage.removeItem("updataById");
    localStorage.removeItem("name");
    localStorage.setItem("updataById",id);
    localStorage.setItem("name",name);
    $('#middle-reght').load('../html/user/userUpdata.html');
}
function updataRoleById(id,name) {
    localStorage.removeItem("updataRoleById");
    localStorage.removeItem("updataRoleByName");
    localStorage.setItem("updataRoleById",id);
    localStorage.setItem("updataRoleByName",name);
    $('#middle-reght').load('../html/user/userRoleUpdata.html');
}

function userJurisdictionUpdateById(id,name) {
    localStorage.removeItem("userJurisdictionUpdateById");
    localStorage.removeItem("userJurisdictionUpdateByName");
    localStorage.setItem("userJurisdictionUpdateById",id);
    localStorage.setItem("userJurisdictionUpdateByName",name);
    $('#middle-reght').load('../html/user/userJurisdictionUpdate.html');
}


// function FindAlls() {
//     let data=myAjax("/user/findAll","","get");
//     data=data.list;
//     let html='';
//     for (let i=0;i<data.length;i++){
//         html+='        <tr>\n' +
//             '            <td>'+data[i].id+'</td>\n' +
//             '            <td>'+data[i].code+'</td>\n' +
//             '            <td>'+data[i].typeName+'</td>\n' +
//             '            <td>'+data[i].name+'</td>\n' +
//             '            <td>'+data[i].sex+'</td>\n' +
//             '            <td>'+data[i].age+'</td>\n' +
//             '            <td>'+data[i].education+'</td>\n' +
//             '            <td>'+data[i].university+'</td>\n' +
//             '            <td><div class="biaos">'+data[i].naative+'</div></td>\n' +
//             '            <td><div class="biaos">'+data[i].address+'</div></td>\n' +
//             '            <td>'+data[i].phone+'</td>\n' +
//             '            <td>'+data[i].otherphone+'</td>\n' +
//             '            <td>'+data[i].groupCode+'</td>\n' +
//             '            <td><input type="button" value="编辑" onclick="updataById('+data[i].id+')"><input type="button" value="删除" onclick="deleteById('+data[i].id+')"></td>\n' +
//             '        </tr>';
//     }
//     $("#userFandAll").html(html);
// }